package com.dahai.gameinfo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Test {
    public static void main(String[] args) throws Exception {
        // 1.导入驱动类
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.用户信息和url
        String url = "jdbc:mysql://111.229.154.169:3306/shop?useUnicode=true&characterEncoding=utf8&useSSL=false";
        String user = "dahai";
        String password = "dahai";
        // 3.获取连接
        Connection conn = DriverManager.getConnection(url, user, password);
        // 4.执行SQL的对象
        Statement sta =  conn.createStatement();
        // 5.执行SQL
        String sql = "select * from account";
        ResultSet rs = sta.executeQuery(sql);
        while (rs.next()){
            System.out.println("id= " + rs.getObject("id"));
            System.out.println("name= " + rs.getObject("name"));
            System.out.println("money= " + rs.getObject("money"));
            System.out.println("=========================================");
        }
        // 6.释放连接
        rs.close();
        sta.close();
        conn.close();
    }
}
